package com.note.app.document;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;

/**
 * 笔记内容文档
 */
@Data
@Document(collection = "note_content")
@Schema(description = "笔记内容")
public class NoteContent {

    /**
     * 内容ID
     */
    @Id
    @Schema(description = "MongoDB ID")
    private String id;

    /**
     * 关联的笔记ID
     */
    private Long noteId;

    /**
     * 笔记内容 (Markdown格式)
     */
    private String content;

    /**
     * 版本号
     */
    private Integer version;

    /**
     * 创建人ID
     */
    private Long createdBy;

    /**
     * 创建时间
     */
    private LocalDateTime createdAt;

    /**
     * 更新人ID
     */
    @Column(name = "created_at")
    private Long updatedBy;

    /**
     * 更新时间
     */
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    /**
     * 返回内容的诊断信息
     */
    @Override
    public String toString() {
        return "NoteContent{" +
                "id='" + id + '\'' +
                ", noteId=" + noteId +
                ", contentLength=" + (content != null ? content.length() : 0) +
                ", hasContent=" + StringUtils.hasText(content) +
                ", version=" + version +
                ", createdBy=" + createdBy +
                ", createdAt=" + createdAt +
                ", updatedBy=" + updatedBy +
                ", updatedAt=" + updatedAt +
                '}';
    }
    
    /**
     * 验证内容是否完整
     */
    public boolean isValid() {
        return StringUtils.hasText(content) && 
               noteId != null && 
               (version != null || version == 0);
    }
}